﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace 重载构造函数
{
    class Program
    {
        static void Main(string[] args)
        {
            Time time1 = new Time(); //00:00:00
            Time time2 = new Time(2);  //02:00:00
            Time time3 = new Time(21, 34); //21:34:00
            Time time4 = new Time(27, 74, 99);//00:00:00
            Time time5 = new Time(time3); // 21:34:00

            Console.WriteLine("Constructed width:\n");

            time1.Display("no-parameter constructor:");
            time2.Display("Hour supplied,Minute and Second defaulted:");
            time3.Display("Hour and Minute supplied, Second defaulted:");
            time4.Display("Hour Minute and Second all supplied:");
            time5.Display("Another Time object has been supplied:");

            Console.WriteLine("=================拓展方法====================");
            time5.DisplayTime();
            Time time6 = time5.AddTime(5);
            time6.DisplayTime();
            Console.ReadKey();
        }//end method Main
    }//end class program

    //extension-class method 
    static class TimeExtensions
    {
        #region Time类的拓展方法DisplayTime

        public static void DisplayTime(this Time atime)
        {
            Console.WriteLine("{0}\n", atime.ToString());
        }//end extension-method of class Time DisplayTime

        #endregion

        /// <summary>
        /// 拓展方法AddTime
        /// </summary>
        /// <param name="atime"></param>
        /// <param name="hours"></param>
        /// <returns>Time</returns>
        public static Time AddTime(this Time atime, int hours)
        {
            Time newtime = new Time();

            newtime.Second = atime.Second;
            newtime.Minute = atime.Minute;
            newtime.Hour = (atime.Hour + hours) % 24;

            return newtime;
        }//end extension-method of class Time AddTime
    }//end class TimeExtensions 
}
